"""
# 1、修改元素的属性/移除元素的属性 - 了解
# document.getElementByXXX(XXX).setAttribute("name","lemon")
# document.getElementByXXX(XXX).RemoveAttribute("name")
"""
from selenium import  webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# 封装的意思：把相同类似的代码放到一个函数里面,重复使用
def wait_element_clickable(locator):
    web_element = WebDriverWait(driver,8,0.5).until(EC.element_to_be_clickable(locator))
    return web_element

def wait_element_visible(locator):
    #web_element代表通过显示等待找到的元素
    web_element =  WebDriverWait(driver, 8, 0.5).until(EC.visibility_of_element_located(locator))
    return web_element

def wait_element_presence(locator):
    #web_element代表通过显示等待找到的元素
    web_element =  WebDriverWait(driver, 8, 0.5).until(EC.presence_of_element_located(locator))
    return web_element

driver = webdriver.Chrome()
driver.get('http://mall.lemonban.com:3344/')
driver.maximize_window()
wait_element_clickable((By.LINK_TEXT,'登录')).click()
wait_element_visible((By.XPATH,'//input[@placeholder="请输入手机号/用户名"]')).send_keys('lemon_py')
wait_element_visible((By.XPATH,'//input[@placeholder="请输入密码"]')).send_keys('12345678')
wait_element_clickable((By.CLASS_NAME,'login-button')).click()
sleep(2)  # 一定要等待2s
wait_element_clickable((By.XPATH,'//span[text()="个人中心"]')).click()
wait_element_clickable((By.LINK_TEXT,'收货地址')).click()
wait_element_clickable((By.LINK_TEXT,'新增收货地址')).click()
sleep(2)

# js修改属性操作
ele = driver.find_element(By.XPATH,'//div[@prop="province"]//input')
# 删除readonly属性
# driver.execute_script("arguments[0].removeAttribute('readonly')",ele)
driver.execute_script("arguments[0].setAttribute('placeholder','123')",ele)
sleep(1)
# ele.send_keys("黄花机场")

sleep(4)
# driver.quit()